package com.neuedu.common.file.domain.model.enums;

import lombok.Getter;

import cn.hutool.core.util.StrUtil;

public enum FileTypeEnum {

    WORD(new String[]{"doc", "docm", "docx"}, "Microsoft Word"),

    PDF(new String[]{"pdf"}, "可移植文档格式文件"),

    EXCEL(new String[]{"xls", "xlsm", "xlsx"}, "Microsoft Excel"),

    VISIO(new String[]{"vsd", "vsdm", "vsdx"}, "Microsoft Visio"),

    CSV(new String[]{"csv"}, "逗号分隔值文件"),

    MD(new String[]{"md"}, "Markdown 轻量级标记语言文件"),

    PPT(new String[]{"ppt", "pptm", "pptx"}, "Microsoft PowerPoint"),

    PSD(new String[]{"psd"}, "Adobe Photoshop 文件"),

    RAR(new String[]{"rar"}, "Roshal Archive 压缩文件"),

    IMAGE(new String[]{"jpg", "jpeg", "png", "bmp", "gif"}, "图片"),

    MP3(new String[]{"mp3"}, "MPEG Layer-3 音频文件"),

    MP4(new String[]{"mp4"}, "MPEG 4 视频"),

    M3U8(new String[]{"m3u8"}, "MPEG 4 视频"),

    ZIP(new String[]{"zip"}, "压缩文件"),

    AVI(new String[]{"avi"}, "音频视频交错电影或声音文件"),

    MOV(new String[]{"mov"}, "Apple QuickTime 电影文件"),

    MSI(new String[]{"msi"}, "Microsoft 安装程序文件"),

    EXE(new String[]{"exe"}, "可执行程序文件"),

    BAT(new String[]{"bat"}, "Windows 批处理文件"),

    JAR(new String[]{"jar"}, "Java 体系结构文件"),

    AAC(new String[]{"aac", "adt", "adts"}, "Windows 音频文件"),

    TXT(new String[]{"txt"}, "无格式文本文件"),

    UNKNOWN(new String[]{}, "未知格式"),
    ;

    @Getter
    private final String[] suffixes;

    @Getter
    private final String desc;

    FileTypeEnum(String[] suffixes, String desc) {
        this.suffixes = suffixes;
        this.desc = desc;
    }

    public static FileTypeEnum getBySuffix(String suffixStr) {
        if (StrUtil.isBlank(suffixStr)) {
            return UNKNOWN;
        }
        suffixStr = StrUtil.trim(suffixStr).toLowerCase();
        final FileTypeEnum[] values = FileTypeEnum.values();
        for (FileTypeEnum fileType : values) {
            for (String suffix : fileType.getSuffixes()) {
                if (suffixStr.equalsIgnoreCase(suffix)) {
                    return fileType;
                }
            }
        }

        return UNKNOWN;
    }

}
